<template>
	<view class="recharge">
		<view style="padding-bottom: 20rpx;display: flex;flex-direction: column;gap: 10rpx;">
			<view class="recharge-title">
				当前用户
			</view>
			<view class="recharge-title" style="font-size: 28rpx;" :style="{color:themeColor.main_color}">
				{{userInfo.nickName}}  {{userInfo.phone}}
			</view>
		</view>
		<view style="padding-bottom: 20rpx;display: flex;flex-direction: column;gap: 10rpx;">
			<view class="recharge-title">
				当前金额
			</view>
			<view class="recharge-title" style="font-size: 48rpx;" :style="{color:themeColor.main_color}">
				￥{{userInfo.user_monery}}
			</view>
		</view>
		<view class="recharge-title">
			充值金额
		</view>
		<view class="recharge-money" v-if="balanceList.length > 0">
			<view class="recharge-money-item" v-for="(item,index) in balanceList" :key="index" :class="activeIndex == index?'active':''" @click="selectMoney(index)">
				<view class="recharge-item-money">
					{{ item.currency_balance }}<span>元</span>
				</view>
				
				<view class="recharge-item-tip">
					赠送:{{item.give_cash}}
				</view>
			</view>
		</view>
		
		<view class="recharge-title h-m-t-20">
			充值说明
		</view>
		<view class="recharge-tip">
			<view>1.充值所得金额仅该小程序可用。</view>
			<view>2.该充值功能未调用微信支付，点击充值即可。</view>
			<view>3.最终解释权在开发者手中。</view>
		</view>
		
		<view class="recharge-buttom-box" v-if="balanceList.length > 0">
			<view class="buttom-left" style="display: flex;justify-content: center;align-items: center;">
				<view class="buttom-left-info">付款金额</view>
				<view class="buttom-left-money" :style="{color:themeColor.main_color}">¥ {{ balanceList[activeIndex].payment_cash }}</view>
			</view>
			
			<view :style="{background:themeColor.main_color}" class="buttom-right" @click="okEvent">
				立即充值
			</view>
		</view>
		
	</view>
</template>

<script>
	 
	export default {
		data() {
			return {
				moneyList:[{'id':0,'money':100},{'id':1,'money':200},{'id':2,'money':300},{'id':3,'money':400}],
				activeIndex: 0,
				themeColor:'',
				wechatConfig:'',
				balanceList:[],
				userInfo:''
			};
		},
		onLoad() {
		
			
			this.getBalance();
			this.getH5Login();
			setTimeout(()=>{
				this.themeColor = this.$store.state.themeConfig || uni.getStorageSync('themeConfig')
				this.wechatConfig = this.$store.state.wechatConfig ||  uni.getStorageSync('wechatConfig')
			},500)
		},
		methods:{
			getH5Login(){
				this.tui.request("/basic-capi/h5LoginRefresh", "post", {
					openid:uni.getStorageSync("userInfo")['openid']
				}).then((res) => {
					uni.setStorageSync('userInfo',res.data.userInfo)
					this.userInfo = res.data.userInfo
				}).catch((res) => {
					console.log(res)
				})
			},
			getBalance(){
				this.tui.request("/basic-capi/getBalance/list", "get",{
					pageNum:1,
					pageSize:8,
				}).then((res) => {
					if(res.code == 200){
						this.balanceList = res.data.list
					}
				}).catch((res) => {
					console.log(res)
				})
			},
			/* 选择充值金额 */
			selectMoney(index){
				this.activeIndex = index
			},
			async okEvent(){
				this.tui.toast("暂未开通支付功能!")
				
				// let _this = this
				// const res = await updateUserMoney({
				// 	money: _this.moneyList[_this.activeIndex].money,
				// 	openid: uni.getStorageSync("openid")
				// })
				// if(res.data.code == 200){
				// 	let user = uni.getStorageSync("userInfo")
				// 	user.money += _this.moneyList[_this.activeIndex].money
				// 	uni.setStorageSync("userInfo",user)
					
				// 	uni.showToast({
				// 		title:'充值成功',
				// 		icon:'none'
				// 	})
					
				// }
			}
		}
	}
</script>

<style lang="scss">
	.recharge{
		margin: 30rpx;
		// position: fixed;
		.recharge-title{
			color: #333333;
			font-weight: bold;
		}
		
		.recharge-tip{
			margin-top: 20rpx;
			
			view{
				font-size: 28rpx;
				color: #666666;
				margin-top: 10rpx;
			}
		}
		
		.recharge-money{
			display: flex;
			align-items: center;
			overflow: hidden;
			overflow-x: scroll;
			margin-top: 10rpx;
			z-index: 999;
			.recharge-money-item:first-child{
				margin-left: 0;
			}
			
			.recharge-money-item{
				margin: 20rpx 10rpx;
				width: 280rpx;
				height: 360rpx;
				border: 2rpx solid #efefef;
				border-radius: 30rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				box-sizing: border-box;
				box-shadow: #f0f0f0 0px 1px 8px 0;
				flex-shrink: 0;
				
				.recharge-item-money{
					font-size: 60rpx;
					color: #333;
					
					span{
						font-size: 28rpx;
					}
				}
				
				.recharge-item-tip{
					padding: 6rpx 20rpx;
					font-size: 24rpx;
					background: #efefef50;
					border-radius: 40rpx;
					margin-top: 20rpx;
					color: #666666;
				}
			}
			
			.active{
				background-image: url("");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				border: none;
				animation: float 0.7s 1;
			}
			
			@keyframes float {
			    from {
			        transform: translatey(0px) scale(1);
			    }
			
			    50% {
			        transform: translatey(-2px) scale(1.01);
			    }
			
			    to {
			        transform: translatey(0px) scale(1);
			    }
			}
		}
		.recharge-buttom-box{
			position: fixed;
			bottom: 0;
			width:calc(100vw - 60rpx);
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 80rpx;
			padding-top: 20rpx;
			border-top: 2rpx dashed #efefef;
			box-sizing: border-box;
			
			.buttom-left{
				font-size: 28rpx;
				display: flex;
				align-items: flex-end;
				
				.buttom-left-money{
					font-weight: bold;
					font-size: 40rpx;
					margin-left: 20rpx;
					line-height: 38rpx;
					
				}
				 
				.buttom-left-money::first-letter{
					font-weight: normal;
					font-size: 28rpx;
				}
			}
			
			.buttom-right{
				padding: 16rpx 58rpx;
				background: #333;
				color: #fff;
				border-radius: 50rpx;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}
</style>
